import { listPageItemType } from './types';
export function initBaseTreeListItem(list: Array<any>, pathArr: Array<any> = [], rootOptions: any) {
  const { labelKey = 'label', keyKey = 'key', haveChildKey = 'haveChild' } = rootOptions;
  const list_: Array<listPageItemType> = [];
  list.forEach(i => {
    const key = i[keyKey];
    const label = i[labelKey];
    const haveChild = i[haveChildKey];
    const keyArr_: Array<any> = [];
    const labelArr_: Array<any> = [];
    pathArr.forEach(i => {
      if (i.key !== null) {
        keyArr_.push(i.key);
        labelArr_.push(i.label);
      }
    });
    keyArr_.push(key);
    labelArr_.push(label);
    list_.push({
      label,
      key,
      keyArr: keyArr_,
      labelArr: labelArr_,
      haveChild,
    });
  });
  return list_;
}

export function initBaseSearchListItem(list: Array<any>, rootOptions: any) {
  const { labelKeySearch = 'label', keyKeySearch = 'key', keyArrKeySearch = 'keyArr' } = rootOptions;
  const list_: Array<listPageItemType> = [];
  list.forEach(i => {
    const key = i[keyKeySearch];
    const label = i[labelKeySearch];
    const keyArr_ = i[keyArrKeySearch];
    const labelArr_: Array<any> = [];
    list_.push({
      label,
      key,
      keyArr: keyArr_,
      labelArr: labelArr_,
    });
  });
  return list_;
}

